package org.openeccos.util;

import com.sas.framework.expojo.servlet.ExpojoServletFilter;

public class TestFilter extends ExpojoServletFilter {

//	@Override
//	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws java.io.IOException, ServletException {
//		
//		ModelExposer modelExposer = null;
//
//		try {
//			HttpSession session = ((HttpServletRequest) request).getSession();
//
//			// Get the ModelExposer if one already exists or create it
//			modelExposer = (ModelExposer) session.getAttribute(ATTR_MODEL_EXPOSER);
//			if (modelExposer == null) {
//				// ModelExposer not yet created so create it and assign it to the session
//				modelExposer = ExpojoServletContextListener.get().createModelExposer();
//				session.setAttribute(ATTR_MODEL_EXPOSER, modelExposer);
//			}
//
//			// Dependency injection takes place here by attaching this session's ModelExposer 
//			// to this current thread that is about to be used to service this request
//			modelExposer.attachThread();
//
//			// Begin a transaction for this request
//			//modelExposer.persistenceProvider.open();
//			modelExposer.persistenceProvider.beginTx();
//
//			// Call next filter in the chain or the servlet if no more filters
//			chain.doFilter(request, response);
//
//			// Commit any changes made during this init call
//			modelExposer.persistenceProvider.commitTx();
//		} catch (ServletException e) {
//			System.out.println("Exception thrown while servicing HTTP request: " + e);
//			e.printStackTrace();
//
//			for (Throwable cause = e.getRootCause(); cause != null; cause = cause.getCause()) {
//				System.out.println("Caused by: " + cause);
//				cause.printStackTrace();
//			}
//
//			modelExposer.persistenceProvider.rollbackTx();
//		} finally {
//			// Request has been processed using this current thread so detach the ModelExposer 
//			// from this thread
//			//modelExposer.persistenceProvider.close();
//			modelExposer.detachThread();
//		}
//	}

}
